﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Jzy.Model.Project;
using Frame.Lib.Core.Base;

namespace Jzy.DAL.Project
{
    public class PrjTaskDAL:BaseDAL
    {
        private int _prjID;
        public PrjTaskDAL(int prjID)
        {
            _prjID = prjID;
        }
        public object GetRootID()
        {
            string sql = "select ID from " + OTableName.PrjTask + " where PrjID=@p0 and UpperID=0";
            DataTable dt = dbOper.Query(sql, _prjID);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                return dt.Rows[0][0];
            }
        }

        public void SetStatistic(PrjTaskInfo info)
        {
            string sql = "select min(StartTime),max(EndTime),sum(TimeLimit),sum(Workload),avg([Percent]) from " + OTableName.PrjTask + " where UpperID = @p0";
            DataTable dt = dbOper.Query(sql,info.ID);
            if (dt.Rows[0][0] != DBNull.Value)
            {
                info.StartTime = (DateTime)dt.Rows[0][0];
                info.EndTime = (DateTime)dt.Rows[0][1];
                info.TimeLimit = (double)dt.Rows[0][2];
                info.Workload = (int)dt.Rows[0][3];
                info.Percent = (int)dt.Rows[0][4];
            }
        }

        
    }
}
